package ysq.xyg.host.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.host.model.po.HostAdvise;
import ysq.xyg.host.model.vo.HostAdviseVo;
import ysq.xyg.host.service.HostAdviseService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 房产模块-建议信息controller层
 *
 * @author shengQiang yu
 * @date 2019-7-5 22:08:51
 */
@RestController
public class HostAdviseController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(HostAdviseController.class);
    @Resource
    private HostAdviseService hostAdviseService;

    private HostAdvise hostAdvise;

    /**
     * 分页查询
     *
     * @param hostAdviseVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-7-5 22:08:51
     */
    @BaseLog(module = "房产模块",className = "建议信息",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostAdvise/page",method = RequestMethod.POST)
    public ReturnEntity page(HostAdviseVo hostAdviseVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = hostAdviseService.page(hostAdviseVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-5 22:08:51
     */
    @RequestMapping(value = "/hostAdvise/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/host/hostAdviseUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            List<HostAdvise> hostAdviseList = hostAdviseService.listLeft(new HostAdviseVo(id));
            if(hostAdviseList!=null&&hostAdviseList.size()>0){
                hostAdvise=hostAdviseList.get(0);
            }
            view.addObject("hostAdvise", hostAdvise);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-5 22:08:51
     */
    @BaseLog(module = "房产模块",className = "建议信息",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostAdvise/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return hostAdviseService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param hostAdviseVo Vo对象
     * @author shengQiang yu
     * @date 2019-7-5 22:08:51
     */
    @BaseLog(module = "房产模块",className = "建议信息",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostAdvise/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,HostAdviseVo hostAdviseVo){
        return hostAdviseService.addOrUpdate(hostAdviseVo,acceptCurrentUser(request));
    }
}